package com.sunday.canal.adapter.mongo.support;

import com.alibaba.otter.canal.protocol.CanalEntry;
import lombok.Builder;
import lombok.Data;
import org.apache.commons.lang.SerializationUtils;
import org.bson.Document;

/**
 * @Description: 事件数据
 * @Author: zsy
 * @Create: 2020/2/6 21:23
 */
@Data
@Builder
public class EventData {

    private String tableName;

    private CanalEntry.EventType eventType;

    private Document query;

    private Document documents;

    public Document merge() {
        Document document = (Document) SerializationUtils.clone(this.documents);
        query.entrySet().stream().forEach(q -> document.put(q.getKey(), q.getValue()));
        return document;
    }

}
